package com.example.system.service.impl;


import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.commons.core.entity.SystemDepartment;
import com.example.system.mapper.SystemDepartmentMapper;
import com.example.system.service.ISystemDepartmentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 部门表 服务实现类
 * </p>
 *
 * @author lk
 * @since 2024-08-24
 */
@Service
public class SystemDepartmentServiceImpl extends ServiceImpl<SystemDepartmentMapper, SystemDepartment> implements ISystemDepartmentService {

    @Override
    public List<Tree<String>> getDeptList() {
        List<SystemDepartment> systemDepartments = baseMapper.selectList(new LambdaQueryWrapper<>());
        return TreeUtil.build(systemDepartments,"0",(systemMenu, tree) ->{
            tree.setId(systemMenu.getId().toString());
            tree.putExtra("deptName",systemMenu.getDeptName());
            tree.setParentId(systemMenu.getParentId().toString());
            tree.putExtra("status", systemMenu.getStatus());
            tree.putExtra("remark", systemMenu.getRemark());
            tree.putExtra("createTime",systemMenu.getCreateTime());
        });
    }
}
